package bog

class EditDropDownTagLib {
    def ownerDropDown = {attrs ->
        if (attrs.threadInstance.status == ThreadStatus.OPEN) {
        out << "<span class='btn-group'>"
        out << "<a class='btn dropdown-toggle' data-toggle='dropdown' href='#'>Actions"
        out << "<span class='caret'></span></a>"
        out << "<ul class='dropdown-menu'>"
            out << "<li><a href='${createLink(controller: 'question', action: 'edit', id: attrs.threadInstance.question.id)}'><i class='icon-edit'></i><span class='offset1'>Edit</span></a></li>"
            out << "<li><a href='${createLink(controller: 'thread', action: 'updateStatus', id: attrs.threadInstance.question.id, params: [status: ThreadStatus.SOLVED])}'><i class='icon-ok'></i><span class='offset1'>Solved</span></a></li>"
        out << "</ul>"
        out << "</span>"
        }
    }

    def adminDropDown = {attrs ->
        out << "<span class='btn-group'>"
        out << "<a class='btn dropdown-toggle' data-toggle='dropdown' href='#'>Actions"
        out << "<span class='caret'></span></a>"
        out << "<ul class='dropdown-menu'>"
        out << "<li><a href='${createLink(controller: 'question', action: 'edit', id: attrs.threadInstance.question.id)}'><i class='icon-edit'></i><span class='offset1'>Edit</span></a></li>"
        if (attrs.threadInstance.status != ThreadStatus.OPEN)
            out << "<li><a href='${createLink(controller: 'thread', action: 'updateStatus', id: attrs.threadInstance.question.id, params: [status: ThreadStatus.OPEN])}'><i class='icon-folder-open'></i><span class='offset1'>Open</span></a></li>"
        if (attrs.threadInstance.status != ThreadStatus.SOLVED)
            out << "<li><a href='${createLink(controller: 'thread', action: 'updateStatus', id: attrs.threadInstance.question.id, params: [status: ThreadStatus.SOLVED])}'><i class='icon-ok'></i><span class='offset1'>Solved</span></a></li>"
        if (attrs.threadInstance.status != ThreadStatus.CLOSED)
            out << "<li><a href='${createLink(controller: 'thread', action: 'updateStatus', id: attrs.threadInstance.id, params: [status : ThreadStatus.CLOSED])}'><i class='icon-remove'></i><span class='offset1'>Close</span></a></li>"
        out << "</ul>"
        out << "</span>"
    }
}
